/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
// block copy text
(function($) {
    if ($.browser.mozilla) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : 'none'
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : ''
                });
            });
        };
    } else if ($.browser.msie) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('selectstart.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('selectstart.disableTextSelect');
            });
        };
    } else {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('mousedown.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('mousedown.disableTextSelect');
            });
        };
    }
})(jQuery);
//

$j = jQuery.noConflict();
$j(document).ready(function(){
    // block copy data
    $j(".rich-table-row").disableTextSelect();
    $j(".item").disableTextSelect();
    $j(document).bind("contextmenu",function(e){
        return false;
    });
    //  show tim kiem box
    $j('.img_search').live('click',function(){
                $j(this).parent().next().css('display','block');
        });
        $j('.close_search').live('click',function(){
                $j(this).parent().parent().css('display','none');
        });
    var ctrlDown = false;
    var ctrlKey = 17, vKey = 86, cKey = 67, aKey = 65, cmdKey = 224;

    $j(document).keydown(function(e)
    {
        if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = true;
    }).keyup(function(e)
    {
        if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = false;
    });

    //                    $j(document).keydown(function(e)
    //                    {
    //                       
    //                        if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey || e.keyCode == aKey)   ){
    //                            if(e.keyCode == cKey){
    //                                alert(message8);
    //                            }
    //                                
    //                            return false;
    //                        }
    //
    //                    });
    // check permission
    if($j('.permission').attr('lang') == 'false'){
        window.location.href = "accessdenied.jsp";
    }
    $j('a.fancybox').live('mouseenter', function(){
        var dWidth ;// = parseInt($j(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
        var dHeight;// =  parseInt($j(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
        $j(this).fancybox({
            'width':dWidth-20,
            'height':dHeight,
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'          : 'inline'
        });
    });
    
    $j(".iconmenunew1").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=1',function(data){       
          
            });
       
    });
    $j(".iconmenunewtl").live("click",function(){
        $j.post('actionmenusetting.jsp?stepmenu=99',function(data){               
            });     
    });
    $j(".logo").live("click",function(){
        $j.post('actionmenusetting.jsp?stepmenu=100',function(data){            
            });            
    });
    $j(".iconmenunew2").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=2',function(data){
                    
            });
              
    });
    $j(".iconmenunew3").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=3',function(data){
                    
            });
              
    });
    $j(".iconmenunew4").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=4',function(data){
                    
            });
              
    });
    $j(".iconmenunew5").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=5',function(data){
                    
            });
              
    });
    $j(".iconmenunew6").live("click",function(){
        $j.post('actionmenusetting.jsp?stepmenu=6',function(data){
            
            });
              
    });
    $j(".iconmenunew7").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=7',function(data){
                    
            });
              
    });
    $j(".iconmenunew8").live("click",function(){

        $j.post('actionmenusetting.jsp?stepmenu=8',function(data){
                    
            });
              
    });
    // fancybox
    $j('a.fancybox').each(function(){
        var dWidth=0 ;// = parseInt($j(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
        var dHeight =0;//=  parseInt($j(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
        $j(this).fancybox({
            'width':dWidth-20,
            'height':dHeight,
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'          : 'inline'
        });
    });
    // fancybox frame
    $j('a.fancyboxiframe').each(function(){
        var dWidth=0;//  = parseInt($j(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
        var dHeight=0;// =  parseInt($j(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
        $j(this).fancybox({
            'width':dWidth-20,
            'height':dHeight,
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'          : 'iframe'
        });
    });
 
});
function searchClient(){
    $j('.text_search').live('keyup',function(){

        $j('.item').hide();
        $j('.tabs_menu').hide();
        $j('.item').each(function(){
            html = $j(this).html();
            //alert($j('.text_search').val());
            // alert( ununicode(html));  || html.indexOf( $j('.keysearch').val()) > -1
            if(   html.indexOf( $j('.text_search').val()) > -1    )  {
                $j(this).show();
            }else{
                $j(this).hide();
            }

        });
    });
}
function swapMenu(){
    /*fullPath = window.location.pathname;
     filename = fullPath.replace(/^.*[\\\/]/, '').toString();
    $j('.select_menu').each(function() {
        tam = $j(this).children().attr('href').toString();
        if( (tam).indexOf(filename) > -1 ){

            string1 = $j(this).children().attr('href');
            string2 = $j(this).children().html();
            $j('.select_menu_choice').children().attr('href',string1)
            $j('.select_menu_choice').children().html(string2);



        }
    }); */
    if($j('#isadmin').val() == 'true'){
        $j('.m1').hide();
        $j('.m1').next().hide();
        $j('.m2').show();
      
 
    }else{
        $j('.m2').hide();
        $j('.m2').next().hide();
        $j('.m1').show();

    }

    swap('mainmenu1','m1');
    swap('mainmenu2','m2');
    swap('submenu1','s1');
    swap('submenu2','s2');
    swap('submenu3','s3');

}
function swap(myid, myclass){
    object = $j('#'+myid).val();
    href = $j('.'+object).children().attr('href');
    html = $j('.'+object).children().html();
    $j('.'+myclass).children().attr('href',href)
    $j('.'+myclass).children().html(html);

}
//initial thickbox
function initThickBox(elementThickBox){
    $j(elementThickBox).live('click',function(e){
        e.preventDefault();
        tb_show("",$j(this).attr('href'), "");
    });

    tb_init(elementThickBox);//pass where to apply thickbox
    imgLoader = new Image();// preload image
    imgLoader.src = tb_pathToImage;
}
function showFancybox(elementFancybox){
    $j(elementFancybox).live('click',function(e){
        showPleaseWait1(); 
    });
}

//validate form
 
function validateform(id)
{
    
                 
              
    $j("#"+id).validate({
        });
    $j("#"+id + " :input").live('keypress',function(){
        $j('.alert').html('');
        $j('.error-message').html('');
    });
       
    //required field
    // set element class is 'required'
    //date field
    // set element class is 'date'
    $j('.date').each(function() {
        $j(this).setMask('39/19/2999');
    });
    //email field
    // set element class is 'email'
    //number field
    // set element class is 'number'
    $j('.number').each(function() {
        $j(this).setMask('99999999999');
    });
    //equal field muon bang truong nao thi truyen id cua truong do vao thuoc tinh lang vi du lang='password'

    $j('.equalto').each(function() {
        $j(this).rules("add", {
            equalTo:'#'+ id + "\\:" + $j(this).attr('lang')

        });
    // alert($j('#'+ id + "\\:" + $j(this).attr('lang')).attr('class'));
    });

    //max length   muon length bao nhieu thi set cho lang cua thuoc tinh co gia tri bay nhiu  vi du lang='2'
    $j('.maxlength').each(function() {
        $j(this).rules("add", {
            maxlength : $j(this).attr('lang')
        });
    });
        
    //min length muon min length bao nhieu thi set cho alt cua thuoc tinh co so bay nhieu vi du alt='2' co nghia la minlength=2
    $j('.minlength').each(function() {
        $j(this).rules("add", {
            minlength : $j(this).attr('alt')

        });
    });


}
function validatecheck(id)
{

    $j('.error-message').html('');
   
    return $j("#"+id).valid();
}
//show - hide please
function showPleaseWait(){
    Richfaces.showModalPanel('ajaxLoadingModalBox',{
        width:200,
        top:200
    });
    setTimeout(function(){
        hidePleaseWait();
    }, 5000);
}
function showPleaseWait1(){
    Richfaces.showModalPanel('ajaxLoadingModalBox',{
        width:200,
        top:200
    });
    setTimeout(function(){
        hidePleaseWait();
    }, 2000);
}
function hidePleaseWait(){
    Richfaces.hideModalPanel('ajaxLoadingModalBox');
}
function globalReportSlideOut(){
   
    setTimeout(function(){
        $j('#globalReport').slideUp(1000,function(){
            
            });
    }.bind(this), 1500);
}

function showGlobalReport(){
  
    $j('#globalReport').css('left', screen.width/2 - 150);
    $j.post('globalreport.jsp?report=remove&27032a1c799b2395a95af5b1d4617cfc',function(data){
        if(data!=null){
            $j('#globalReport').slideDown(2000,function(){
                globalReportSlideOut();
 
            }); 
          
        }
    });
   
    
}

function Tab4Kapi(){
    //      $j('.fields_more > .select_choise').live('click',function(){
    //
    //         $j('.tab1'+$j(this).attr('lang')).trigger('click');
    //        $j(this).parent('.item').next('.tabs_menu').removeClass('tabs_menu');
    //        $j('.tabs_menu').slideUp();
    //        $j(this).parent('.item').next().addClass('tabs_menu');
    //        $j(this).parent('.item').next('.tabs_menu').slideToggle();
    //
    //      });
    $j('.st_tab').live('click',function(){

        var spanE = $j(this).parent().parent().parent().parent().find('.item_description');
        //alert(spanE.attr('class'));
        var flag=0;
        //showPleaseWait();
         
        if( $j(this).hasClass("st_tab_active")){
            flag=1;
        }
        $j('.st_tab_active').removeClass('st_tab_active');
        spanE.hide();
        if(flag == 0){
            Slide($j(this),spanE);
        }
    //hidePleaseWait();
    });
    $j('.tabs_menu').css('display','none');
    tab = gup( 'tab' );
    if(tab != null && tab !=undefined && tab.length > 0){
        $j('.'+tab).parent().parent().parent().parent().parent('.tabs_menu').css('display','block');
        $j('.'+tab).trigger('click') ;
        
    } 
    $j('.menu-context').live('click',function(){

        tab = $j(this).attr('lang');
        // $j('.tabs_menu').hide();
        //$j(this).parent().parent().parent().parent().removeClass('showchildren');
        $j('.'+tab).parent().parent().parent().parent().parent('.tabs_menu').css('display','block');
            
        $j('.'+tab).trigger('click') ;
           
    });
    $j('.close').on('touchend', function(e) {

        });
    $j('.close').live('click', function(e) {
        $j('.tabs_menu').hide();
    });
       
}
function Slide(object1,object2){
    object1.addClass('st_tab_active');
    object1.children().addClass('st_tab_active');
    file = object1.attr('lang');
    id = object1.attr('id');
    itemid = object1.attr('itemid');
    fullPath = window.location.pathname;
    reload = fullPath.replace(/^.*[\\\/]/, '');
    $j('.item_description').html('');
    if(file != undefined){
        // alert(file+"?id="+id);
        $j.post(file+"?id="+id +"&page="+reload+"&itemid="+itemid,function(data){
            if(data!=null) {
                object2.html(data);
                object2.slideDown();

            }
        });
    }
}
function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}






